﻿using System;
using System.Collections;
using UnityEngine;

// Token: 0x02000228 RID: 552
public class CameraShake : MonoBehaviour
{
	// Token: 0x06000B98 RID: 2968 RVA: 0x00060870 File Offset: 0x0005EA70
	private void Start()
	{
		if (this.debugMode)
		{
			this.ShakeCamera();
		}
	}

	// Token: 0x06000B99 RID: 2969 RVA: 0x00060883 File Offset: 0x0005EA83
	private void ShakeCamera()
	{
		this.startAmount = this.shakeAmount;
		this.startDuration = this.shakeDuration;
		if (!this.isRunning)
		{
			base.StartCoroutine(this.Shake());
		}
	}

	// Token: 0x06000B9A RID: 2970 RVA: 0x000608B8 File Offset: 0x0005EAB8
	public void ShakeCamera(float amount, float duration)
	{
		this.shakeAmount += amount;
		this.startAmount = this.shakeAmount;
		this.shakeDuration += duration;
		this.startDuration = this.shakeDuration;
		if (!this.isRunning)
		{
			base.StartCoroutine(this.Shake());
		}
	}

	// Token: 0x06000B9B RID: 2971 RVA: 0x00060914 File Offset: 0x0005EB14
	private IEnumerator Shake()
	{
		this.isRunning = true;
		while (this.shakeDuration > 0.01f)
		{
			Vector3 rotationAmount = UnityEngine.Random.insideUnitSphere * this.shakeAmount;
			rotationAmount.z = 0f;
			this.shakePercentage = this.shakeDuration / this.startDuration;
			this.shakeAmount = this.startAmount * this.shakePercentage;
			this.shakeDuration = Mathf.Lerp(this.shakeDuration, 0f, Time.deltaTime);
			if (this.smooth)
			{
				base.transform.localRotation = Quaternion.Lerp(base.transform.localRotation, Quaternion.Euler(rotationAmount), Time.deltaTime * this.smoothAmount);
			}
			else
			{
				base.transform.localRotation = Quaternion.Euler(rotationAmount);
			}
			yield return null;
		}
		base.transform.localRotation = Quaternion.identity;
		this.isRunning = false;
		yield break;
	}

	// Token: 0x040010C6 RID: 4294
	public bool debugMode;

	// Token: 0x040010C7 RID: 4295
	public float shakeAmount;

	// Token: 0x040010C8 RID: 4296
	public float shakeDuration;

	// Token: 0x040010C9 RID: 4297
	private float shakePercentage;

	// Token: 0x040010CA RID: 4298
	private float startAmount;

	// Token: 0x040010CB RID: 4299
	private float startDuration;

	// Token: 0x040010CC RID: 4300
	private bool isRunning;

	// Token: 0x040010CD RID: 4301
	public bool smooth;

	// Token: 0x040010CE RID: 4302
	public float smoothAmount = 5f;
}
